
cc.Class({
    extends: cc.Component,

    properties: {
        musicButton:{
            default:null,
            type:cc.Node
        },

        vibrationButton:{
            default:null,
            type:cc.Node
        },

        bgNode:{
            default:null,
            type:cc.Node
        },

        contentNode:{
            default:null,
            type:cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
    },

    start () {

    },

    // update (dt) {},

    onGameSettingCloseButtonClicked:function (event) {
        this.gameUIMgr._hideSetting()
    },

    initSetting:function (gameUIMgr) {
        this.gameUIMgr = gameUIMgr
        let musicOn = cc.sys.localStorage.getItem('user_setting_music_on')
        if(!musicOn){
            musicOn = cc.gg.enumConfig.SETTING.ON
        }else {
            musicOn = parseInt(musicOn)
        }
        this.musicButton.getComponent("SwitchButton").initSwitchButton(musicOn)
        this.musicButton.getComponent("SwitchButton").setFrame1Cb(function () {
            cc.find("Canvas/SoundManager").emit("sound_on")
        }.bind(this))
        this.musicButton.getComponent("SwitchButton").setFrame2Cb(function () {
            cc.find("Canvas/SoundManager").emit("sound_off")
        }.bind(this))

        let vibrationOn = cc.sys.localStorage.getItem('user_setting_vibration_on')
        if(!vibrationOn){
            vibrationOn = cc.gg.enumConfig.SETTING.ON
        }else {
            vibrationOn = parseInt(vibrationOn)
        }
        this.vibrationButton.getComponent("SwitchButton").initSwitchButton(vibrationOn)
        this.vibrationButton.getComponent("SwitchButton").setFrame1Cb(function () {
            cc.find("Canvas/SoundManager").emit("vibration_on")
        }.bind(this))
        this.vibrationButton.getComponent("SwitchButton").setFrame2Cb(function () {
            cc.find("Canvas/SoundManager").emit("vibration_off")
        }.bind(this))
    },

    _showBgMask:function () {
        this.bgNode.active = true
        this.bgNode.width = cc.winSize.width
        this.bgNode.height = cc.winSize.height
        let middlePos = cc.find("Canvas").convertToWorldSpaceAR(cc.Vec2.ZERO)
        this.bgNode.position = this.bgNode.parent.convertToNodeSpaceAR(middlePos)
    },

    _hideBgMask:function () {
        this.bgNode.active = false
        // this.bgNode.width = cc.winSize.width
        // this.bgNode.height = cc.winSize.height
        // this.bgNode.position = cc.Vec2.ZERO
    },

    showGameSetting:function () {
        cc.log("显示dealinfo了！")
        this._showBgMask()
        cc.gg.logicUtil.windowEnterFromTop(this.contentNode)
    },

    hideGameSetting:function () {
        this._hideBgMask()
        cc.gg.logicUtil.windowOutToBottom(this.contentNode)
    },
});
